
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        ul{
            display: flex;    
        }
        li{
            width: 90px;
            height: 50px;
            border: 1px solid #999999;
            text-align: center;
            line-height: 50px;
            font-size: 20px;
            font-weight: 600;
            list-style: none;
            margin-left: 10px;
        }
        .on{
            background-color: seagreen;
            color: seashell;
        }
    </style>
</head>
<body>
        <ul>
            <li class="on">灰色</li>
            <li>绿色</li>
            <li>白色</li>
            <li>蓝色</li>
        </ul>
</body>
<script>
    var lis = document.querySelectorAll('li')
    for(var i = 0; i < lis.length; i++){
        lis[i].onclick=function(){
            if(this.className == ''){
                this.className = 'on'
            }else{
                this.className = ''
            }
        }
    }
</script>
</html>